/*封装ajax方法*/
//引入axios
import axios  from 'axios'
export default function ajax(url,data={},params=true,type='GET'){
   if(type==='GET'){
     if(params){
        data={
          params:data
        }
        return axios.get(url,data);
     }else{
       let strData='';
       Object.keys(data).forEach(key=>{
         strData+=key+'='+data[key]+'&';
       });
       if(strData!==''){
         strData=strData.substring(0,strData.length-1);//去除最后一个'&'
         url+='?'+strData;
       }
       return axios.get(url);
     }


   }
   else{
      return axios.post(url,data)
   }
}
